InStr Function

Returns the position of the first occurrence of a String inside another String. The first character is numbered 1.

Syntax

result = InStr( [start], source, find )

result = stringVariable.InStr( [start], find )


Parameters

start (Optional)

Integer

Optional position from which to begin searching the source string. One is the default if omitted.

source

String

Required. String expression being searched.

find

String

Required. String expression being sought.



Notes

If the find string is not found within the source string, 0 (zero) is returned. If the find string is an empty string, then start is returned. That is, InStr("This","") returns 1 and InStr(3,"This","") returns 3.

InStr is case-insensitive, even with accented Roman characters and non-Roman alphabets.

If you need to find the byte position of the find string within the source string, use the InStrB function or you need a case-sensitive function.


Examples

This example uses the InStr function to locate a string within another string.

Dim first As Integer
first = InStr ("This is a test", "t")
//returns 1
first = InStr("This is a test", "is")    
//returns 3
first = InStr(4, "This is a test", "is")  
//returns 6
first = InStr("This is a test", "tester")
//returns 0

See Also

Asc, Chr, Left, Len, Mid, NthField, Right, Split, StrComp functions.